package cn.funeralobjects.ams.web.api;

import cn.funeralobjects.ams.web.model.MProductApi;
import cn.funeralobjects.ams.web.model.VProductApi;
import cn.funeralobjects.ams.web.model.VProductApiAccessDto;
import cn.funeralobjects.common.web.api.RestNameApi;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Mono;

/**
 * Api of ProductApi
 *
 * @author FuneralObjects
 * Create date: 2020/5/28 2:07 PM
 */
@Validated
public interface ProductApiApi extends BaseAmsApi<VProductApi, MProductApi, Integer>, RestNameApi<VProductApi, Integer> {

    /**
     * 查询某产品内的实体
     *
     * @param productId 产品id
     * @param action    api方法
     * @param version   版本号
     * @return 实体
     */
    @GetMapping(value = "/product-{productId}", params = {"action", "version"})
    Mono<VProductApi> findByActionAndVersionInProduct(@PathVariable Integer productId,
                                                      @RequestParam("action") String action,
                                                      @RequestParam("version") String version
    );

    /**
     * 通过编码获取资源关联的密钥
     *
     * @param code    编码
     * @param action  action
     * @param version 版本号
     * @return 密钥key
     */
    @GetMapping(value = "/product-res/access-key", params = {"code", "action", "version"})
    Mono<VProductApiAccessDto> getExistsAccessKey(@RequestParam("code") String code, @RequestParam("action") String action, @RequestParam("version") String version);

    /**
     * 绑定accessKey
     *
     * @param prodResId 资源id
     * @param apiId     apiId
     * @param accessId  秘钥id
     * @return 无返回
     */
    @PostMapping(value = "/product-res/access-key", params = {"prod-res-id", "prod-api-id", "access-id"})
    Mono<Void> bindAccessKey(@RequestParam("prod-res-id") Integer prodResId, @RequestParam("prod-api-id") Integer apiId, @RequestParam("access-id") Integer accessId);
}
